using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using NCS.Library;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Zones;
using NCS.Module.CMS.Web.HomePage;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class HomeZone : CMSWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object zone_active_obj = this.Portal[Definition.Portal_Zone_Active + "_" + AppEnv.PortalId() + "_" + AppEnv.GetLanguage()];
            int zone_active_id = 0;
            if(zone_active_obj != null)
                zone_active_id = Int32.TryParse(zone_active_obj.ToString(), out zone_active_id) ? zone_active_id : 0;

            if (zone_active_id == 0)
            {
                //DataTable tbl = ZoneController.GetZones(0, Int32.Parse(AppEnv.PortalId()), 0);
                DataTable tbl = ZoneController.GetZonesVisbleInNavbar();
                if (tbl != null && tbl.Rows.Count >= 0)
                {
                    if (tbl.Rows.Count > 1)
                    {
                        HeadZone headzone;
                        for (int i = 0; i < tbl.Rows.Count; i++)
                        {
                            headzone = (HeadZone)LoadControl("HeadZone.ascx");
                            headzone.LoadZone(Int32.Parse(tbl.Rows[i]["Zone_ID"].ToString()));
                            this.PlaceHolder1.Controls.Add(headzone);
                        }
                    }
                    else if (tbl.Rows.Count == 0)
                    {
                        this.PlaceHolder1.Controls.Add(LoadControl("ContentList.ascx"));
                    }
                }
            }
            else
            {
                this.PlaceHolder1.Controls.Add(LoadControl("ContentList.ascx"));
            }
        }
    }
}